home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / Aidan's Class Libraries / Source / Action / Application.cpp < prev    next >
Encoding:
Text File  |  1997-07-06  |  2.8 KB  |  131 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include <Events.h>
  5. #include <QuickDraw.h>
  6. #include <Windows.h>
  7. #include <Dialogs.h>
  8. #include <Menus.h>
  9. #include <Fonts.h>
  10. #include "CLApplication.h"
  11. #include "CLCleanup.h"
  12. #include "CLActionHandler.h"
  13. #include "CLKeyboardHandler.h"
  14. #include "CLMouseHandler.h"
  15. #include "CLNullHandler.h"
  16. #include "CLWindowLayer.h"
  17. #include "CLFloatLayer.h"
  18. #include "CLModalLayer.h"
  19.  
  20. TApplication *TApplication::shCurApp = 0l;
  21.  
  22. TApplication::TApplication()
  23. {
  24.     InitGraf( &qd.thePort );
  25.     InitFonts();
  26.     InitWindows();
  27.     InitMenus();
  28.     InitDialogs(0l);
  29.     TEInit();
  30.     InitCursor();
  31.     FlushEvents( everyEvent, 0 );
  32.     for( int i= 0; i<16; i++ )
  33.         SetDeviceHandler( 1<<i, 0 );
  34.     shCurApp = this;
  35.     mhKeyboard= new TKeyboardHandler();
  36.     SetDeviceHandler( keyDownMask|keyUpMask|autoKeyMask, mhKeyboard );
  37.     mhMouse= new TMouseHandler();
  38.     SetDeviceHandler( mDownMask|mUpMask, mhMouse );
  39.     SetDeviceHandler( osMask|activMask, this );
  40.     mhNull= new TNullHandler();
  41.     SetDeviceHandler( 1, mhNull );
  42.     ::GetGWorld( &mhWorld, &mhDevice );
  43.     gFloatingWindowLayer= new TFloatingWindowLayer;
  44.     gNormalWindowLayer= new TWindowLayer;
  45.     gFloatingWindowLayer->AddLayer( gNormalWindowLayer );
  46.     gModalWindowLayer= new TModalLayer();
  47. }
  48.  
  49. void TApplication::Quit()
  50. {
  51.     MEventDispatcher::Quit();
  52.     delete mhKeyboard;
  53.     delete mhMouse;
  54.     delete mhNull;
  55. }
  56.  
  57. void TApplication::AddBackgrounder( MBackgrounder *item )
  58. {
  59.     UInt32 data;
  60.  
  61.     if( mBackGrounds.FindIndex( item ) != -1 )
  62.         return;
  63.     mBackGrounds.MoveLast();
  64.     mBackGrounds.AddNext( item );
  65. }
  66.  
  67. void TApplication::RemoveBackgrounder( MBackgrounder *item )
  68. {
  69.     SInt16 index;
  70.  
  71.     index= mBackGrounds.FindIndex( item );
  72.     if( index == -1 )
  73.         return;
  74.     mBackGrounds.GoToElem( index );
  75.     mBackGrounds.Remove();
  76. }
  77.  
  78. void TApplication::DispatchEvent( const EventRecord &ev )
  79. {
  80.     BuildEvent( ev );
  81.     mClean.Clean();
  82. }
  83.  
  84. void TApplication::BuildEvent( const EventRecord &ev )
  85. {
  86.     switch( ev.what ) {
  87.     case osEvt:
  88.         if( ((ev.message>>24)==suspendResumeMessage) ) {
  89.             TBackgroundEvent bev;
  90.             bev.when= ev.when;
  91.             bev.background= (ev.message&resumeFlag)==0;
  92.             MBackgrounder *item;
  93.             if( mBackGrounds.MoveFirst() ) {
  94.                 do {
  95.                     mBackGrounds.GetData( item );
  96.                     item->HandleBackground( &bev );
  97.                 } while( mBackGrounds.MoveNext() );
  98.                 return;
  99.             }
  100.         } else if( ((ev.message>>24)==mouseMovedMessage) )
  101.             mhMouse->DispatchEvent( ev );
  102.         break;
  103.     case activateEvt:
  104.         /*if( TFloatingWindow::sFloatList.MoveFirst() )
  105.             return;
  106.         TBaseWindow *win=((TBaseWindow*)GetWRefCon( (WindowRef)ev.message ));
  107.         win->MakeActive( (ev.modifiers&activeFlag)==activeFlag );*/
  108.         break;
  109.     }
  110. }
  111.  
  112. void TApplication::NewDispatcher()
  113. {
  114. }
  115.  
  116. void TApplication::OldDispatcher()
  117. {
  118. }
  119.  
  120. void TApplication::GetGlobalWorld( GWorldPtr &world, GDHandle &device )
  121. {
  122.     world= mhWorld;
  123.     device= mhDevice;
  124. }
  125.  
  126. GrafPtr TApplication::GetGlobalPort()
  127. {
  128.     GrafPtr port;
  129.     ::GetWMgrPort( &port );
  130.     return( port );
  131. }